package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.Rejected;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 退货表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-12-05
 */
@Mapper
public interface RejectedMapper extends BaseMapper<Rejected> {

    /**
     * 获取最大编号
     * @param code
     * @return
     */
    @Select("SELECT MAX(rejected_code) FROM dragon_rejected WHERE rejected_code LIKE CONCAT(#{code},'%')")
    String maxRoundInoutNumber(String code);

    @Select("select dr.*,da.username from dragon_rejected dr " +
            "left join dragon_admin da on dr.admin_id = da.id " +
            "left join dragon_contract dc on dr.contract_id = dc.id " +
            " ${ew.customSqlSegment}")
    Page<Rejected> selectItemPage(Page<Rejected> rejectedPage, @Param(Constants.WRAPPER) Wrapper<Rejected> wrapper);

    @Select("select dr.*,da.username from dragon_rejected dr " +
            "left join dragon_admin da on dr.admin_id = da.id " +
            "left join dragon_contract dc on dr.contract_id = dc.id " +
            "where dr.id = #{id}")
    Rejected selectDetailById(Integer id);
}
